
$(function () {
    init_validates();
})

/*form验证规则*/
function init_validates(){
    var $saleTagForm = $("#saleStage_createGrouping_form");
    var icon = "<i class='zmdi zmdi-close-circle zmdi-hc-fw color-red'></i> ";
     $saleTagForm.validate({
        rules:{
            tagGroupName:{
                required:true,
                minlength:1,
                maxlength:6,
                remote:{
                    url:ctx+"saleConfig/checkGroupName",
                    type: "get",
                    dataType: "json",
                    data: {
                        tagGroupName: function (){
                            return $("#tagGroupName").val().trim();
                        }
                    }
                }
            }
        },
        messages:{
            tagGroupName:{
                required: icon + "请输入分组名称",
                minlength: icon + "分组名称长度1到6个字符",
                maxlength: icon + "分组名称长度1到6个字符",
                remote: icon + "分组名称已经存在"
            }
        }
    });
}
/*创建分组*/
function createGrouping(){
    var url = ctx+"saleConfig/createGrouping";
    var $saleTagForms = $("#saleStage_createGrouping_form").validate().form();
    if($saleTagForms){
        $.post(url,$("#saleStage_createGrouping_form").serialize(),function(r){
            if (r.code === 0) {
                $("#sale-modal").modal('hide');
                getAllTagGroup();
                $JuXue.n_success(r.msg);
            } else {
                $JuXue.n_danger(r.msg);
            }
        });
    }
}